package com.admin.kotlintest.activity.setting

import android.os.Bundle
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.SaveListener
import com.admin.kotlintest.R
import com.admin.kotlintest.base.BaseActivity
import com.admin.kotlintest.bean.Car
import com.admin.kotlintest.config.FixedValue
import com.admin.kotlintest.utils.DataUtil
import com.socks.library.KLog
import kotlinx.android.synthetic.main.activity_add_car.*
import kotlinx.android.synthetic.main.layout_title.*
import org.jetbrains.anko.toast

/**
 * Created by 吴昶 on 2018/4/13.
 */
class AddCarActivity:BaseActivity(){

    override fun bindLayout(): Int {
        return R.layout.activity_add_car
    }

    override fun initData() {
        tv_title.text="添加车辆"
    }

    override fun initEvent() {
        btn_save_car.setOnClickListener {
            if(edt_car_number.text.toString()==""){
                toast("请输入车牌号码")
            }else if(DataUtil.isStringFoematRight(edt_car_number.text.toString(),FixedValue.CAR_NUMBER)){
                toast("请输入正确的车牌号码")
            }else{
                var car=Car()
                car.carNumber=edt_car_number.text.toString()
                car.save(object : SaveListener<String>() {
                    override fun done(p0: String?, p1: BmobException?) {
                        p1?:let {
                            toast("车辆添加成功")
                            finish()
                        }
                        p1?.let {
                            KLog.d(p1.message)
                        }
                    }
                })
            }
        }

        iv_title_left.setOnClickListener {
            finish()
        }
    }
}